package com.ruoyi.project.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.SysWechatPay;
import com.ruoyi.project.system.service.ISysWechatPayService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 微信支付Controller
 *
 * @author hongwj
 * @date 2024-02-06
 */
@RestController
@RequestMapping("/system/wechatPay" )
@Slf4j
public class SysWechatPayController extends BaseController {
    @Autowired
    private ISysWechatPayService sysWechatPayService;

    /**
     * 查询微信支付列表
     */
    @PreAuthorize("@ss.hasPermi('system:wechat_pay:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(SysWechatPay sysWechatPay) {
        startPage();
        List<SysWechatPay> list = sysWechatPayService.selectSysWechatPayList(sysWechatPay);
        return getDataTable(list);
    }

    /**
     * 查询所有微信支付列表
     */
    @PreAuthorize("@ss.hasPermi('system:wechat_pay:all')" )
    @Log(title = "微信支付" , businessType = BusinessType.OTHER)
    @GetMapping("/all/wechatPays" )
    public AjaxResult all(SysWechatPay sysWechatPay) {
        List<SysWechatPay> list = sysWechatPayService.selectSysWechatPayList(sysWechatPay);
        return success(list);
    }

    /**
     * 导出微信支付列表
     */
    @PreAuthorize("@ss.hasPermi('system:wechat_pay:export')" )
    @Log(title = "微信支付" , businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, SysWechatPay sysWechatPay) {
        List<SysWechatPay> list = sysWechatPayService.selectSysWechatPayList(sysWechatPay);
        ExcelUtil<SysWechatPay> util = new ExcelUtil<SysWechatPay>(SysWechatPay. class);
        util.exportExcel(response, list, "微信支付数据" );
    }

    /**
     * 获取微信支付详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:wechat_pay:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return success(sysWechatPayService.selectSysWechatPayById(id));
    }

    /**
     * 新增微信支付
     */
    @PreAuthorize("@ss.hasPermi('system:wechat_pay:add')" )
    @Log(title = "微信支付" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysWechatPay sysWechatPay) {
        return toAjax(sysWechatPayService.insertSysWechatPay(sysWechatPay));
    }

    /**
     * 修改微信支付
     */
    @PreAuthorize("@ss.hasPermi('system:wechat_pay:edit')" )
    @Log(title = "微信支付" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysWechatPay sysWechatPay) {
        return toAjax(sysWechatPayService.updateSysWechatPay(sysWechatPay));
    }

    /**
     * 删除微信支付
     */
    @PreAuthorize("@ss.hasPermi('system:wechat_pay:remove')" )
    @Log(title = "微信支付" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysWechatPayService.deleteSysWechatPayByIds(ids));
    }
}
